package fm.last.api
{
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;
    
    import fm.last.Agent;
    import fm.last.RestAPI;
    
    final public class ArtistAPI extends RestAPI
    {
        // those in comment are not implemented yet
        public static const ARTIST_ADD_TAG:String        = "artist.addTags";
        public static const ARTIST_GET_EVENTS:String     = "artist.getEvents"; 
        public static const ARTIST_GET_IMAGES:String     = "artist.getImages"; 
        public static const ARTIST_GET_INFO:String       = "artist.getInfo";
        public static const ARTIST_GET_SHOUTS:String     = "artist.getShouts"; 
        public static const ARTIST_GET_SIMILAR:String    = "artist.getSimilar";
        public static const ARTIST_GET_TAGS:String       = "artist.getTags";
        public static const ARTIST_GET_TOP_ALBUMS:String = "artist.getTopAlbums";
        public static const ARTIST_GET_TOP_FANS:String   = "artist.getTopFans";
        public static const ARTIST_GET_TOP_TAGS:String   = "artist.getTopTags";
        public static const ARTIST_GET_TOP_TRACKS:String = "artist.getTopTracks";        
        public static const ARTIST_REMOVE_TAG:String     = "artist.removeTag";
        public static const ARTIST_SEARCH:String         = "artist.search";
        public static const ARTIST_SHARE:String          = "artist.share";
        public static const ARTIST_SHOUT:String          = "artist.shout";
        
        public function ArtistAPI(agent:Agent)
        {
            super(agent);
        }

        /* ********************************************************************/
        

        /** artist.addTags */
        public function addTags(onComplete:Function, 
                                   onError:Function,
                                   artist:String, 
                                   tags:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_ADD_TAG;
            urlVars["artist"] = artist;
            urlVars["tags"] = tags;
            requestAPI(URLRequestMethod.POST, urlVars, true, onComplete, onError);        
        }
        

        /** artist.getEvents */
        public function getEvents(onComplete:Function, 
                                   onError:Function,
                                   artist:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_GET_EVENTS;
            urlVars["artist"] = artist;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
         
         
        /** artist.getImages */
        public function getImages(onComplete:Function, 
                                   onError:Function,
                                   artist:String,
                                   page:int=-1,
                                   limit:int=-1,
                                   order:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_GET_IMAGES;
            urlVars["artist"] = artist;
            if (page>0)  urlVars["page"]  = page;
            if (limit>0) urlVars["limit"] = limit;
            if (order!=null) urlVars["order"] = order;            
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
         

        /** artist.getInfo */
        public function getInfo(onComplete:Function, 
                                   onError:Function,
                                   artist:String=null,
                                   mbid:String=null,
                                   lang:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_GET_INFO;
            if (artist!=null) urlVars["artist"] = artist;
            if (mbid!=null)   urlVars["mbid"]   = mbid;            
            if (lang!=null)   urlVars["lang"]   = lang;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** artist.getShouts */
        public function getShouts(onComplete:Function, 
                                   onError:Function,
                                   artist:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_GET_SHOUTS;
            urlVars["artist"] = artist;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** artist.getSimilar */
        public function getSimilar(onComplete:Function, 
                                   onError:Function,
                                   artist:String, 
                                   limit:int=-1):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_GET_SIMILAR;
            urlVars["artist"] = artist;
            if (limit > 0) {
                urlVars["limit"] = limit;
            }
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** artist.getTags */
        public function getTags(onComplete:Function, 
                                onError:Function,
                                artist:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_GET_TAGS;
            urlVars["artist"] = artist;
            requestAPI(URLRequestMethod.GET, urlVars, true, onComplete, onError);        
        }


        /** artist.getTopAlbums */
        public function getTopAlbums(onComplete:Function, 
                                   onError:Function,
                                   artist:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_GET_TOP_ALBUMS;
            urlVars["artist"] = artist;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** artist.getTopFans */
        public function getTopFans(onComplete:Function, 
                                   onError:Function,
                                   artist:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_GET_TOP_FANS;
            urlVars["artist"] = artist;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** artist.getTopTags */
        public function getTopTags(onComplete:Function, 
                                   onError:Function,
                                   artist:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_GET_TOP_TAGS;
            urlVars["artist"] = artist;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** artist.getTopTracks */
        public function getTopTracks(onComplete:Function, 
                                   onError:Function,
                                   artist:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_GET_TOP_TRACKS;
            urlVars["artist"] = artist;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
                

        /** artist.removeTag */
        public function removeTag(onComplete:Function, 
                                   onError:Function,
                                   artist:String, 
                                   tag:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_REMOVE_TAG;
            urlVars["artist"] = artist;
            urlVars["tag"] = tag;
            requestAPI(URLRequestMethod.POST, urlVars, true, onComplete, onError);        
        }
        

        /** artist.search */
        public function search(onComplete:Function, 
                                   onError:Function,
                                   artist:String,
                                   page:int=-1,
                                   limit:int=-1):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_SEARCH;
            urlVars["artist"] = artist;
            if (page>0)  urlVars["page"]  = page;
            if (limit>0) urlVars["limit"] = limit;
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);        
        }
        

        /** artist.share */
        public function share(onComplete:Function, 
                              onError:Function,
                              artist:String,
                              recipient:String,
                              message:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_SHARE;
            urlVars["artist"] = artist;
            urlVars["recipient"] = recipient;
            if (message!=null) urlVars["message"] = message;
            requestAPI(URLRequestMethod.POST, urlVars, true, onComplete, onError);        
        }
        

        /** artist.shout */
        public function shout(onComplete:Function, 
                              onError:Function,
                              artist:String,
                              message:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = ArtistAPI.ARTIST_SHOUT;
            urlVars["artist"] = artist;
            urlVars["message"] = message;
            requestAPI(URLRequestMethod.POST, urlVars, true, onComplete, onError);        
        }  
    }
}